package com.mix;

import com.aspose.words.*;
import org.springframework.core.io.ClassPathResource;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Date;

public class AsposeWordUtil {

    public static void main(String[] args) throws Exception {
        putWatermark2();
    }

    // 比较Word
    public static void compareWord() throws Exception {
        // 创建一个新的文档
        Document doc1 = new Document("C:\\Users\\zhoubin\\Desktop\\代码集合\\file-util\\test-files\\比较两个word文件的差异\\原版.docx");
        Document doc2 = new Document("C:\\Users\\zhoubin\\Desktop\\代码集合\\file-util\\test-files\\比较两个word文件的差异\\修订版.docx");
        doc1.compare(doc2, "小明", new Date());
        // 保存文档
        doc1.save("C:\\Users\\zhoubin\\Desktop\\代码集合\\file-util\\test-files\\比较两个word文件的差异\\比较结果.docx");
    }

    // 给Workbook加上水印
    private static void putWatermark() throws Exception {
        ClassPathResource resourceIn = new ClassPathResource("files\\比较两个word文件的差异\\原版.docx");
        InputStream in = new FileInputStream(resourceIn.getFile().getCanonicalFile());
        com.aspose.words.Document doc = new com.aspose.words.Document(in);
        TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
        textWatermarkOptions.setFontFamily("宋体");
        textWatermarkOptions.setFontSize(40f);
        textWatermarkOptions.setColor(java.awt.Color.RED);
        textWatermarkOptions.setLayout(WatermarkLayout.length);
        textWatermarkOptions.isSemitrasparent(false);
        doc.getWatermark().setText("水印内容f3f2    ffffffffffffffffffffffff", textWatermarkOptions);
        doc.save("C:\\Users\\zhoubin\\Desktop\\代码集合\\file-util\\src\\main\\resources\\files\\比较两个word文件的差异\\watermark.docx");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        doc.save(out, com.aspose.words.SaveFormat.DOCX);
        out.close();
        out.toByteArray();
    }

    private static void putWatermark2() throws Exception {
        ClassPathResource resourceIn = new ClassPathResource("files\\比较两个word文件的差异\\原版.docx");
        InputStream in = new FileInputStream(resourceIn.getFile().getCanonicalFile());
        com.aspose.words.Document doc = new com.aspose.words.Document(in);
        WordWatermarkUtil.insertMoreWatermarkText(doc,"水印");
        doc.save("C:\\Users\\zhoubin\\Desktop\\代码集合\\file-util\\src\\main\\resources\\files\\比较两个word文件的差异\\watermark2.docx");
    }
}